<template>
</template>
<style lang="scss">

</style>
<script>
  // import echart from '@/components/report/echart'
  import report from '@/config/report.js';

  export default {
    data() {
      return {};
    },
    created() {
      this.$api.get('/sys/report_assist_new/refresh_auth_cache')
      .then(data => {
        this.skipView();
      })
    },
    mounted() {
    },
    methods: {
      //根据用户所有菜单的第一个有url的菜单跳转到对应页面
      skipView() {
        let url = 'sys/menu/auth_tree';
        this.$api.get(url).then(data => {
          let _data = data.data
          // console.log(_data,'_data');
          for (let i = 0; i < _data.length; i++) {
            if (_data[i].menu_url) {
              sessionStorage.headerActive = _data[i].menu_url;
              //判断如果第一个菜单为驾驶舱时，则跳转到第一个分支驾驶舱
              if (_data[i].menu_url == 'realTime') {
                // console.log(_data[i].children[0].menu_url);
                this.$router.replace({path: _data[i].children[0].menu_url});
              } else {
                this.$router.replace({path: _data[i].menu_url});
              }
              return;
            } else {
              this.traverse(_data[i]);
            }
          }
        })
        .catch(err => {
           console.log(err)
        })
      },
      //遍历子集
      traverse(arr) {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].menu_url) {
            sessionStorage.headerActive = arr[i].menu_url;
            this.$router.replace({name: arr[i].menu_url});
            return
          } else {
            this.traverse(arr[i].children)
          }
        }
      }
    }
  }
</script>
